package com.kunbo.cn.controller.core.purchase;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kunbo.cn.dto.ModulationPriceHistoryDto;
import com.kunbo.cn.entity.core.purchase.ProcurementAdjustment;
import com.kunbo.cn.entity.core.purchase.ProcurementPriceAdjustment;
import com.kunbo.cn.service.core.purchase.ModulationPriceHistoryService;
import com.kunbo.cn.service.core.purchase.ProcurementAdjustmentService;
import com.kunbo.cn.service.core.purchase.ProcurementPriceAdjustmentService;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.ResultBean;

/**
 * 采购调价
 * @author  编写人:刘义
 * @date 时间:2019年1月29日下午3:52:24
 */
@RestController
@RequestMapping("/priceAdjustment")
public class ProcurementPriceAdjustmentController {
	

	@Autowired
	private ProcurementPriceAdjustmentService service;
	
	@Autowired
	private ModulationPriceHistoryService modulationPrice;
	
	
	@RequestMapping("/save")
	public ResultBean<Boolean> save(
			@RequestParam("order_code") String order_code, 
			@RequestParam("receiving_unit") String receiving_unit, 
			@RequestParam("supplier") String supplier, 
			@RequestParam("settlement_method") String settlement_method,
			@RequestParam("orginal_price") float orginal_price,
			@RequestParam("create_user_id") String create_user_id,
			@RequestParam("uuid")String uuid,
			@RequestParam("taskid")String taskid,
			@RequestParam("zxTime")String zxTime,
			@RequestParam("zdPople")String zdPople,
			@RequestParam("zdTime")String zdTime
			){
		ResultBean<Boolean>   result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "成功", "失败", service.save(order_code, receiving_unit, supplier, settlement_method, orginal_price, create_user_id, uuid, taskid,zxTime,zdPople,zdTime));
	}
	
	
	@RequestMapping("/update")
	public ResultBean<Boolean>  update(
			@RequestParam("id") Integer id, 
			@RequestParam("order_code") String order_code, 
			@RequestParam("receiving_unit") String receiving_unit, 
			@RequestParam("supplier") String supplier,
			@RequestParam("material_classification") String material_classification, 
			@RequestParam("material") String material, 
			@RequestParam("settlement_method") String settlement_method, 
			@RequestParam("orginal_price") Float orginal_price,
			@RequestParam("new_price") Float new_price, 
			@RequestParam("remarks") String remarks
			){
		ResultBean<Boolean>   result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "成功", "失败", service.update(id, order_code, receiving_unit, supplier, material_classification, material, settlement_method, orginal_price, new_price, remarks));
	}
	
	
	
	@RequestMapping("/sel")
	public ResultBean<ProcurementPriceAdjustment> sel(
			@RequestParam("id") Integer id
			){
		ResultBean<ProcurementPriceAdjustment>   result = new  ResultBean<ProcurementPriceAdjustment>();
		return BuildBean.buildResult(result, "成功", "失败", service.sel(id));
	}
	
	
	
	
	
	@RequestMapping("/selByCondition")
	public ResultBean<List<Map<String,Object>>> selByCondition(
			@RequestParam("order_code") String order_code,
			@RequestParam("material") String material,
			@RequestParam("supplier") String supplier,
			@RequestParam("page") Integer page,
			@RequestParam("pageSize") Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "成功", "失败", service.selByCondition(order_code, material, supplier, page, pageSize));
	}
	
	//保存调价
	@RequestMapping("saveModulationPriceHistory")
	public ResultBean<Boolean> saveModulationPriceHistory(
			@RequestParam("uuid")String uuid,
			@RequestParam("create_user_id")String create_user_id,
			@RequestParam("taskid")String taskid,
			@RequestParam("original_price")double original_price,
			@RequestParam("new_price")double new_price,
			@RequestParam("adjustment_time")String adjustment_time,
			@RequestParam("order_code")String order_code
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "成功", "失败", modulationPrice.save(uuid, create_user_id, taskid, original_price, new_price, adjustment_time,order_code));
	}
	
	
	
	//根据订单获取调价历史
	@RequestMapping("getModulationPriceHistory")
	public ResultBean<List<ModulationPriceHistoryDto>> getModulationPriceHistory(
			@RequestParam("order_code")String order_code
			){
		ResultBean<List<ModulationPriceHistoryDto>> result = new ResultBean<List<ModulationPriceHistoryDto>>();
		return BuildBean.buildResult(result, "成功", "失败", modulationPrice.get(order_code));
		
	}
	
	

}
